package cn.hloger.spider.demo.chatgptDemo.controller.api;

import cn.hloger.spider.common.annotation.PackagResp;
import cn.hloger.spider.common.bean.ApiResponse;
import cn.hloger.spider.demo.chatgptDemo.bean.req.ChatApiReq;
import cn.hloger.spider.demo.chatgptDemo.bean.req.ChatMvcReq;
import cn.hloger.spider.demo.chatgptDemo.bean.req.ChatResp;
import cn.hloger.spider.demo.chatgptDemo.bean.resp.ChatApiResp;
import cn.hloger.spider.demo.chatgptDemo.service.ChatgptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * TODO
 *
 * @author huanglong
 * @Description TODO
 * @data 2022/9/12
 */
@RestController
@RequestMapping("/api/chat")
public class ChatgptController {
    @Autowired
    private ChatgptService chatgptService;

    /**
     * 最全的
     */
    @PostMapping("/getMessage")
    public ChatResp getMessage(@RequestBody @Validated ChatMvcReq req) {
        return chatgptService.getMessage(req);
    }

    /**
     * post 可输入大数据
     */
    @PostMapping("/getMessageResult")
    public ApiResponse<String> getMessageResult(@RequestBody @Valid ChatMvcReq req) {
        return ApiResponse.success(chatgptService.getMessageResult(req));
    }

    /**
     * 最简单的
     */
    @GetMapping("/getSimpleMessage")
    public ApiResponse<String> getSimpleMessage(@RequestParam String message) {
        return ApiResponse.success(chatgptService.getSimpleMessage(message));
    }

    @GetMapping("/getSimpleMessage2")
    @PackagResp
    public String getSimpleMessage2(@RequestParam String message) {
        return chatgptService.getSimpleMessage(message);
    }


    @PostMapping("/wechat")
    public ChatApiResp get(@RequestBody @Validated ChatApiReq req) {
        return chatgptService.wechat(req);
    }


    @GetMapping("/cache")
    public String cache(@RequestParam String message) {
        return chatgptService.cache(message);
    }

}
